package com.bd.wechat.controller;


import com.bd.wechat.core.LoginMember;
import com.bd.wechat.core.R;
import com.bd.wechat.entity.Member;
import com.bd.wechat.entity.request.LoginRequest;
import com.bd.wechat.service.MemberService;
import com.bd.wechat.service.impl.WechatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author linhs
 * @menu 小程序端
 * @since 2024-11-15
 */
@Slf4j
@RestController
@RequestMapping("/wechat/member")
public class MemberController {

    @Resource
    private MemberService memberService;

    /**
     * 账号密码登录
     *
     * @param loginRequest
     * @return
     */
    @PostMapping("login")
    public R<String> login(@RequestBody LoginRequest loginRequest) throws Exception {
        String token = memberService.login(loginRequest);
        return R.ok(token);
    }

    /**
     * 注册
     *
     * @param member
     * @return
     */
    @PostMapping("register")
    public R<String> register(@RequestBody @Valid Member member) throws Exception {
        memberService.register(member);
        return R.ok();
    }


    /**
     * 获取用户信息
     *
     * @return
     */
    @GetMapping("/getInfo")
    public R<LoginMember> getInfo() {
        log.info("获取用户信息...");
        return R.ok(memberService.getInfo());
    }

//    /**
//     * 手机号快速验证
//     *
//     * @param code
//     * @return
//     */
//    @PostMapping("loginByUserPhoneNumber")
//    public R loginByUserPhoneNumber(String code) throws Exception {
//        wechatService.getAccessToken(code);
//        return R.ok();
//    }
}

